import logging

logger = logging.getLogger(__name__)

data_store = []
next_id = 1


def get_all_data():
    logger.debug("获取所有数据")
    return data_store


def get_data_by_id(data_id):
    logger.debug(f"通过ID获取数据: {data_id}")
    return next((item for item in data_store if item["id"] == data_id), None)


def create_data(name, description):
    global next_id
    logger.debug(f"创建新数据: {name}, {description}")
    new_data = {"id": next_id, "name": name, "description": description}
    data_store.append(new_data)
    next_id += 1
    return new_data


def update_data(data_id, name, description):
    logger.debug(f"更新数据: {data_id}, {name}, {description}")
    data = get_data_by_id(data_id)
    if data:
        data["name"] = name
        data["description"] = description
    return data


def delete_data(data_id):
    global data_store
    logger.debug(f"删除数据: {data_id}")
    data_store = [item for item in data_store if item["id"] != data_id]
    return True
